package com.example.demo.service.comment.impl;

import com.example.demo.entity.CollectionName;
import com.example.demo.entity.base.EnumState;
import com.example.demo.service.comm.MongodbService;
import com.example.demo.service.comment.CommentService;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @description:
 * @author: cj
 * @create: 15-03-21 15:29:32
 */
@Service
public class CommentServiceImpl implements CommentService {

    @Resource
    MongodbService mongodbService;

    @Resource
    MongoTemplate mongoTemplate;

    @Override
    public Boolean publicCommentWeb(Map<String, Object> map) {
        try {
            Map<String, Object> commentMap = new HashMap<>( 10 );
            commentMap.put( "type", EnumState.STATE_COMMENT_WEB );
            commentMap.put( "giveNumber", 0 );
            commentMap.put( "issueUser", map.get( "issueUser" ) );
            commentMap.put( "content", map.get( "content" ) );
            mongoTemplate.insert( commentMap, CollectionName.COMMENT );
        } catch (Exception e) {
            return false;
        }
        return true;
    }
}
